package com.superman.auth.service;

import cn.hutool.core.util.StrUtil;
import com.superman.auth.exception.ApiDisableException;
import com.superman.auth.exception.NotDataPermissionException;
import com.superman.auth.exception.NotLoginException;
import com.superman.auth.exception.SignException;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 权限服务
 * Author: superman
 * Date: 2024/5/28 18:22
 */
public interface AuthService {

    /**
     * 登录校验
     *
     * @throws NotLoginException 未登录异常
     */
    default void loginCheck(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws NotLoginException {
        // 1、从请求header中获取token
        String authorization = request.getHeader("Authorization");
        if (StrUtil.isBlank(authorization)) throw new NotLoginException();
        // 2、校验token是否过期

    }

    /**
     * 数据权限校验
     *
     * @throws NotDataPermissionException 无数据权限异常
     * @throws ApiDisableException        API禁用异常
     */
    void dataPermissionCheck(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws NotDataPermissionException, ApiDisableException;

    /**
     * 签名检验
     *
     * @throws SignException 签名异常
     */
    void signCheck(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws SignException;


}
